import React from 'react'
import {Select} from "antd";
import { fetchAreaList} from "@/services/public";

class AreaSelect extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      options: []
    }
  }

  componentDidMount() {
    this.fetchAreaList()
  }

  fetchAreaList () {
    fetchAreaList().then((res) => {
      this.setState({
        options: res.data
      })
    })
  }

  render() {
    return (
      <Select
        {...this.props} >
        {
          this.props.disableEmpty?
            null:
          <Select.Option key="" value="">全部</Select.Option>
        }
        {
          this.state.options.map((value) => <Select.Option key={value.id} value={value.name}>{value.name}</Select.Option>)
        }
      </Select>
    )
  }
}

export default AreaSelect
